/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.yczbj.ycvideoplayer.fraction;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.agp.components.TableLayoutManager;

import com.yc.video.config.VideoInfoBean;

import org.yczbj.ycvideoplayer.ConstantVideo;
import org.yczbj.ycvideoplayer.ResourceTable;
import org.yczbj.ycvideoplayer.adapter.TikTok1ListAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Recyclerview Video
 *
 * @since 2021-05-10
 */
public class TikTok1ListFragment extends BaseFraction {
    private List<VideoInfoBean> data = new ArrayList<>();
    private TikTok1ListAdapter mAdapter;
    private ListContainer mListContainer;

    @Override
    protected int getLayoutResId() {
        return ResourceTable.Layout_base_recycler_view;
    }

    @Override
    protected void initComponent(Component rootComponent, Intent intent) {
        mListContainer = (ListContainer) rootComponent.findComponentById(ResourceTable.Id_recyclerView);

        // 模拟请求数据
        List<VideoInfoBean> tiktokBeans = ConstantVideo.getVideoList();
        data.addAll(tiktokBeans);
        TableLayoutManager tableLayoutManager = new TableLayoutManager();
        tableLayoutManager.setColumnCount(2);
        mListContainer.setLayoutManager(tableLayoutManager);
        mAdapter = new TikTok1ListAdapter(getFractionAbility(), data);
        mListContainer.setItemProvider(mAdapter);
    }
}
